package org.leetcode.easy.leetcode383;

import java.util.HashMap;
import java.util.Map;

public class Solution
{
    public boolean canConstruct(String ransomNote, String magazine)
    {
        Map<String,Integer> map = new HashMap<>();

        for (String s : magazine.split("")) {
            Integer time = map.getOrDefault(s, 0);
            map.put(s,time+1);
        }


        for (String s : ransomNote.split("")) {
            Integer time = map.getOrDefault(s, 0);

            if (time<=0)
            {
                return false;
            }else {
                time--;
                map.put(s,time);
            }
        }


        return true;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        boolean b = solution.canConstruct("aa", "aab");
        System.out.println(b);
    }
}
